%
% nc_nm_interp1.m
%
%  Form the 1D linear interpolation matrix for a node centered grid.
%
% input -- Nf = number of nodes on the fine grid
% output -- 
%
function Ip = nc_nm_interp1(Nf, nVoffset);
  
if Nf==3
    if nVoffset==1 % this
        Ip = [1 0; 1/2 1/2; 0 1];
    elseif nVoffset==-1
        Ip = [1/2; 1; 1/2];
    end
    return
end

  % number of variables on the coarse grid
  %
  Nc = (Nf-nVoffset)/2+nVoffset;
  
  % allocate space for the matrix
  %
  Ip = spalloc(Nf,Nc,3*Nc);

  if nVoffset==1
      % first column,  assume homogeneous Dirichlet BC
      %
      Ip(1:2,1) = [1; 0.5];
      % last column, assume homogeneous Dirichlet BC
      %
      Ip(Nf-1:Nf,Nc) = [0.5; 1];
      % loop over columns to set the interpolation operator.
      %
      for j=2:Nc-1
          Ip(2*j-2:2*j,j) = [0.5; 1; 0.5];
      end
  elseif nVoffset==-1
      % assume homogeneous Dirichlet BC
      for j=1:Nc
          Ip(2*j-1:2*j+1,j) = [0.5; 1; 0.5];
      end
  end